package com.example.design.pattern.create.builder;

import java.util.Date;

public class Example {

    private Long id;
    
    private String name;
    
    private String desc;
    
    private Date createTime;
    
    private Date updateTime;

    public Example() {}

    public Example(Example example) {
        this.id = example.getId();
        this.name = example.getName();
        this.desc = example.getDesc();
        this.createTime = example.getCreateTime();
        this.updateTime = example.getUpdateTime();
    }
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "Example [id=" + id + ", name=" + name + ", desc=" + desc + ", createTime=" + createTime
                + ", updateTime=" + updateTime + "]";
    }

    public static Builder builder() {
        return new Builder();
    }
    
    public static final class Builder {
        
        private Example example;
        
        public Builder() {
            example = new Example();
        }
        
        public Builder setId(Long id) {
            example.setId(id);
            return this;
        }
        
        public Builder setName(String name) {
            example.setName(name);
            return this;
        }
        
        public Builder setDesc(String desc) {
            example.setDesc(desc);
            return this;
        }
        
        public Builder setCreateTime(Date createTime) {
            example.setCreateTime(createTime);
            return this;
        }
        
        public Builder setUpdateTime(Date updateTime) {
            example.setUpdateTime(updateTime);
            return this;
        }

        public Example build() {
            return new Example(example);
        }
    }
    
    public static void main(String[] args) {
        Example example = Example.builder().setId(1L)
                                           .setName("")
                                           .setDesc("")
                                           .setCreateTime(new Date())
                                           .setUpdateTime(new Date())
                                           .build();
        System.out.println(example.toString());
    }
}
